# coding=utf-8
import unittest
import os
from unittest import runner
from unittest.case import TestCase, skip
from base_request import req
import HTMLTestRunner
from read_ini import rf
from read_xlsx import rx
from get_test_result import get_key


data = {
    "test01": "aaaaaaaaa"
}
url = rf.open_ini("server", "host")


class Test_case(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        print("-----------test start---------")

    @classmethod
    def tearDownClass(cls):
        print("-----------test ending---------")

    def test01(self):
        for i in range(rx.get_max_row()):  # 0 1 2 3 4 5 6 7
            # print(rx.get_rows_value(i+2),"\n\n\n")
            executive_condition = rx.get_rows_value(i+1)
            # 从第二行开始读取
            if i+1 > 1:
                if executive_condition[2] == "yes":
                    test_number=executive_condition[0]
                    test_method=executive_condition[6]
                    test_url=executive_condition[5]
                    test_data=executive_condition[7]
                    test_result=executive_condition[11]
                    
                    # print(test_method,test_url,test_data,test_result)
                    rqr=req.get_request(test_method,test_url,test_data)
                    # print(rqr)
                    print("\n")
                    if test_result==None:
                        print("第"+test_number+"条用例测试不通过")
                        
                    elif get_key(test_url,"\\return_data.json",test_result)=="success":
                        print("第"+test_number+"条用例测试通过----------------------")
                        
                    else:
                        print("第"+test_number+"条用例测试不通过")
                else:
                    print("这条用例暂不执行")

# if __name__ == "__main__":
    # file_path=os.path.dirname(__file__)+"\\test_result.html"
    # result=open(file_path,"wb")
    # run_test_result=HTMLTestRunner.HTMLTestRunner(stream=result,title="My test unit",description="this is the test for JK")
    
    # suit=unittest.TestSuite()
    # test_unit=[Test_case("test01"),Test_case("test02")]
    # suit.addTests(test_unit)
    # run_test_result.run(suit)

tc=Test_case()
tc.test01()
# print(get_key("test789/abc","\\return_data.json","1003"))